﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR45Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR45Response))]
    public class RR45ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR45Response clazz;
        
        public RR45ResponseSerializer(IRR45Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("veakood");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Veakood))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("veatekst");
            if (clazz.Veatekst!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Veatekst))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Veatekst");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("isik");
            if (clazz.Isik!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR45Response>isik>isik", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.Isik.Count);
                for (int x = 0; ((clazz.Isik != null) 
                            && (x < clazz.Isik.Count)); x = (x + 1)) {
                    if (clazz.Isik[x]!=null) {
                        Writer.WriteStartElement("isik");
                        global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData(clazz.Isik[x]);
                        Writer.WriteTypeAttribute(metaIsik.TypeQualifiedName.Namespace, metaIsik.TypeQualifiedName.Name);
                        metaIsik.NewSerializer(clazz.Isik[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isik");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="veakood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR45Response>veakood");
                }
                clazz.Veakood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("veakood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR45Response>veakood", Reader.LocalName);
            }
            if (Reader.LocalName=="veatekst") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR45Response>veatekst");
                }
                clazz.Veatekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("veatekst")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR45Response>veatekst", Reader.LocalName);
            }
            if (Reader.LocalName=="isik") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR45Response>isik");
                }
                clazz.Isik = new System.Collections.Generic.List<RR45Response.IIsikType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("isik");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "isik")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR45Response>isik>isik");
                        }
                        global::Xtee.Core.SerializationMetadata metaIsik = this.GetMetaData<RR45Response.IIsikType>(Reader, ">>>RR45Response>isik>isik", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR45Response.IIsikType item = metaIsik.NewEntity<RR45Response.IIsikType>();
                        clazz.Isik.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("isik");
                            metaIsik.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR45Response>isik", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR45Response>isik>isik", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR45Response.IsikType))]
        public class IsikTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR45Response.IIsikType clazz;
            
            public IsikTypeSerializer(RR45Response.IIsikType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("isik.Perenimi");
                if (clazz.IsikPerenimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikPerenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikPerenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Eesnimi");
                if (clazz.IsikEesnimi!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikEesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikEesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Staatus");
                if (clazz.IsikStaatus!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikStaatus))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikStaatus");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Sugu");
                if (clazz.IsikSugu!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikSugu))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikSugu");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Synniaeg");
                if (clazz.IsikSynniaeg!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikSynniaeg))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikSynniaeg");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Kodakondsus_riik_kood");
                if (clazz.IsikKodakondsusRiikKood!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikKodakondsusRiikKood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikKodakondsusRiikKood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Kodakondsus_riik_nim");
                if (clazz.IsikKodakondsusRiikNim!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikKodakondsusRiikNim))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikKodakondsusRiikNim");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Synnikoht");
                if (clazz.IsikSynnikoht!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikSynnikoht))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikSynnikoht");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Elamisluba_nr");
                if (clazz.IsikElamislubaNr!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikElamislubaNr))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikElamislubaNr");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Elamisluba_kehtib_kuni");
                if (clazz.IsikElamislubaKehtibKuni!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikElamislubaKehtibKuni))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikElamislubaKehtibKuni");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.Eesti_aadress");
                if (clazz.IsikEestiAadress!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikEestiAadress))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikEestiAadress");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.aadress_liik");
                if (clazz.IsikaadressLiik!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikaadressLiik))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikaadressLiik");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.aadress_kehtib");
                if (clazz.IsikaadressKehtib!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.IsikaadressKehtib))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : IsikaadressKehtib");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("isik.aadress");
                if (clazz.Isikaadress!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikaadress))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikaadress");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="isik.Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Perenimi");
                    }
                    clazz.IsikPerenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Eesnimi");
                    }
                    clazz.IsikEesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Staatus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Staatus");
                    }
                    clazz.IsikStaatus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Staatus")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Staatus", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Sugu") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Sugu");
                    }
                    clazz.IsikSugu = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Sugu")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Sugu", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Synniaeg") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Synniaeg");
                    }
                    clazz.IsikSynniaeg = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Synniaeg")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Synniaeg", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Kodakondsus_riik_kood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Kodakondsus_riik_kood");
                    }
                    clazz.IsikKodakondsusRiikKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Kodakondsus_riik_kood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Kodakondsus_riik_kood", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Kodakondsus_riik_nim") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Kodakondsus_riik_nim");
                    }
                    clazz.IsikKodakondsusRiikNim = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Kodakondsus_riik_nim")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Kodakondsus_riik_nim", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Synnikoht") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Synnikoht");
                    }
                    clazz.IsikSynnikoht = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Synnikoht")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Synnikoht", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Elamisluba_nr") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Elamisluba_nr");
                    }
                    clazz.IsikElamislubaNr = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Elamisluba_nr")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Elamisluba_nr", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Elamisluba_kehtib_kuni") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Elamisluba_kehtib_kuni");
                    }
                    clazz.IsikElamislubaKehtibKuni = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Elamisluba_kehtib_kuni")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Elamisluba_kehtib_kuni", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.Eesti_aadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.Eesti_aadress");
                    }
                    clazz.IsikEestiAadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.Eesti_aadress")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.Eesti_aadress", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.aadress_liik") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.aadress_liik");
                    }
                    clazz.IsikaadressLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.aadress_liik")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.aadress_liik", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.aadress_kehtib") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.aadress_kehtib");
                    }
                    clazz.IsikaadressKehtib = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.aadress_kehtib")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.aadress_kehtib", Reader.LocalName);
                }
                if (Reader.LocalName=="isik.aadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR45Response>isik>isik>isik.aadress");
                    }
                    clazz.Isikaadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("isik.aadress")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR45Response>isik>isik>isik.aadress", Reader.LocalName);
                }
            }
        }
    }
}
